<script lang="ts">
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { getLowcodeApi } from '@/api/lowcode'
import SimpleDefaultPageDetail from './SimpleDefaultPage/components/SimpleDefaultPageDetail.vue'
import { PageDataProperty } from '../types/Lowcode'

export default {
  components: {
    SimpleDefaultPageDetail
  },
  setup() {
    const comp = ref('empty-page')
    let route = useRoute()
    const pageConfig = ref<PageDataProperty>()
    const param = route.params.identifier as string
    getLowcodeApi(param).then((res) => {
      if (!res.data && !res.data.text) {
        throw new Error(res.code)
      }
      pageConfig.value = JSON.parse(res.data.text)
      comp.value = (pageConfig.value?.layout || 'unknown') + '-page-detail'
    })
    return {
      comp,
      pageConfig
    }
  }
}
</script>
<template>
  <!-- {{ pageConfig }} -->
  <component :is="comp" :pageConfig="pageConfig" />
</template>
